<template>
  <div class="home-container">
    <nav class="navbar">
      <span class="welcome-message">欢迎, {{ username }}</span>
      <ul class="nav-menu">
        <li v-for="route in navRoutes" :key="route.path">
          <router-link :to="route.path">{{ route.title }}</router-link>
        </li>
      </ul>
    </nav>

    <main class="content">
      <router-view></router-view>
    </main>
  </div>
</template>

<script>
export default {
  data() {
    return {
      username: localStorage.getItem('userRole') === 'admin' ? '管理员' : '学生',
      navRoutes: []
    };
  },
  created() {
    this.updateNavRoutes();
  },
  watch: {
    $route: 'updateNavRoutes'
  },
  methods: {
    updateNavRoutes() {
      const role = localStorage.getItem('userRole');
      this.navRoutes = [
        { path: '/public-activities', title: '公开活动' }
      ];
      
      if (role === 'admin') {
        this.navRoutes.push({ path: '/activity-management', title: '活动管理' });
      }
    }
  }
};
</script>

<style scoped>
.home-container {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.navbar {
  background-color: #f5f5f5;
  padding: 1rem;
  border-bottom: 1px solid #ddd;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.welcome-message {
  font-weight: bold;
}

.nav-menu {
  list-style-type: none;
  margin: 0;
  padding: 0;
  display: flex;
  gap: 1rem;
}

.nav-menu li {
  display: inline;
}

.nav-menu a {
  text-decoration: none;
  color: #333;
  padding: 0.5rem 1rem;
  border-radius: 4px;
  transition: background-color 0.2s;
}

.nav-menu a:hover,
.nav-menu a.router-link-exact-active {
  background-color: #ddd;
}

.content {
  flex: 1;
  padding: 2rem;
}
</style>